import React from 'react'
import PropTypes from 'prop-types'

class Form extends React.Component {
    constructor(props) {
        super(props)
    }

    componentDidMount() {
        const form = $('#' + this.props.formId)
        $("input,select,textarea",form).not("[type=submit]").jqBootstrapValidation()
    }

    onOK(e) {
        e.preventDefault()
        this.props.saveHandle()
    }

    onCancel(e) {
        e.preventDefault()
        this.props.cancelHandle()
    }

    render() {
        return (
            <div>
                <form className="form-horizontal" id={this.props.formId}>
                    <div className="card-body">
                        {this.props.children}
                    </div>
                    <hr/>  
                    <div className="card-body">
                        <div className="form-group text-right">
                            <button  className="btn btn-info btn-sm waves-effect waves-light m-r-5" onClick={(e)=>{
                                e.preventDefault()
                                this.props.saveHandle()
                            }}>保存</button>
                            <button  className="btn btn-dark btn-sm waves-effect waves-light" onClick={(e)=>{
                                e.preventDefault()
                                this.props.cancelHandle()
                            }}>取消</button>
                        </div>
                    </div>
                </form>      
            </div>
        )
    }
}

Form.propTypes = {
    saveHandle: PropTypes.func.isRequired,
    cancelHandle: PropTypes.func.isRequired,
    formId : PropTypes.string.isRequired
}

export default Form